Andy’s Project Report

Garrett Frady, Ziyang Wang & Tim Moore

2022-12-19

############################### Data setup #####################################

library(readxl) # necessary package to read in .xlsx file
# read in the data
dat1 <- read_xlsx("FPL Consolidated Trial Data_update.xlsx", sheet = 1, 
                  na = "NA")

dat1 <- janitor::clean_names(dat1) 

# add an additional column denoting success as a binary variable; 0 = failure and 1 = success
dat1$success.bin <- ifelse(dat1$success=="yes", 1, 0)

Generalized Linear Mixed Effects Models for Success

#------------------------------------------------------------------------------#
# Generalized Linear Mixed Effects Models - Success as Binary Response Variable #

# in this section, we fit logistic regression models with trial_type, path, ...
# ... and the interaction between trial_type and path as fixed effects; we ...
# ... also include participant_number as a random effects term. 

##### Fit the models #####
library(glmmTMB) # linear and generalized mixed-effects models (with extensions) 
library(dplyr) # package to use piping for data manipulation

# Experiment 1
glmm1 <- glmmTMB(success.bin ~ trial_type*path + (1|participant_number),
                 data = dat1 %>% filter(experiment==1), 
                 family = binomial)

# Experiment 2
glmm2 <- glmmTMB(success.bin ~ trial_type*path + (1|participant_number),
                 data = dat1 %>% filter(experiment==2), 
                 family = binomial)

Visualization

##### Visualization #####

library(ggplot2) # package for visualization

# tables for success
with(dat1 %>% filter(experiment==1), table(success, trial_type, path))
## , , path = E1P1
## 
##        trial_type
## success no_belt yes_belt
##     no        4        0
##     yes      14       18
## 
## , , path = E1P2
## 
##        trial_type
## success no_belt yes_belt
##     no        4        4
##     yes      14       14
## 
## , , path = E1P3
## 
##        trial_type
## success no_belt yes_belt
##     no        0        1
##     yes      18       17
with(dat1 %>% filter(experiment==2), table(success, trial_type, path))
## , , path = E2P1
## 
##        trial_type
## success no_belt yes_belt
##     no       16        1
##     yes       2       17
## 
## , , path = E2P2
## 
##        trial_type
## success no_belt yes_belt
##     no        3        2
##     yes      15       16
## 
## , , path = E2P3
## 
##        trial_type
## success no_belt yes_belt
##     no       12        1
##     yes       6       17
library(gtsummary) # used to get stratified table
# stratified table for success separated by trial_type
dat1 %>% select(success, trial_type, path) %>%
  tbl_strata(strata = path, 
             .tbl_fun = . %>%
               tbl_summary(by = trial_type))
Characteristic E1P1 E1P2 E1P3 E2P1 E2P2 E2P3
no_belt, N = 181 yes_belt, N = 181 no_belt, N = 181 yes_belt, N = 181 no_belt, N = 181 yes_belt, N = 181 no_belt, N = 181 yes_belt, N = 181 no_belt, N = 181 yes_belt, N = 181 no_belt, N = 181 yes_belt, N = 181
success 14 (78%) 18 (100%) 14 (78%) 14 (78%) 18 (100%) 17 (94%) 2 (11%) 17 (94%) 15 (83%) 16 (89%) 6 (33%) 17 (94%)
1 n (%)
# how many individuals success changed when wearing a belt?
# how many stayed the same?
library(tidyr) # data manipulation package
dat1.w1 <- dat1 %>% filter(experiment==1) %>% select(participant_number, trial_type,path,
                                          success.bin) %>%
  pivot_wider(id_cols  = c(participant_number, path), names_from = trial_type, 
              values_from = success.bin)
table("yes-no"=dat1.w1$yes_belt-dat1.w1$no_belt, dat1.w1$path)
##       
## yes-no E1P1 E1P2 E1P3
##     -1    0    3    1
##     0    14   12   17
##     1     4    3    0
# -1 means failed with belt success without
# 0 means stayed the same (either succeeded or failed both) NOTE: noone failed both
# 1 means success with belt, failed without

dat1.w2 <- dat1 %>% filter(experiment==2) %>% select(participant_number, trial_type,path,
                                                     success.bin) %>%
  pivot_wider(id_cols  = c(participant_number, path), names_from = trial_type, 
              values_from = success.bin)
table("yes-no"=dat1.w2$yes_belt-dat1.w2$no_belt, dat1.w1$path)
##       
## yes-no E1P1 E1P2 E1P3
##     -1    1    0    0
##     0    15    7    3
##     1     2   11   15
# -1 means failed with belt success without
# 0 means stayed the same (either succeeded or failed both) NOTE some failed both
# 1 means success with belt, failed without

Success Plotting

# Success Plotting
ggplot(data = dat1 %>% filter(experiment==1), 
       aes(x=trial_type, y = success.bin, color = trial_type), size = 3)+
  geom_jitter(width = 0.5, height=0.05)+
  facet_grid(~path)

ggplot(data = dat1 %>% filter(experiment==2), 
       aes(x=trial_type, y = success.bin, color = trial_type), size = 3)+
  geom_jitter(width = 0.5, height=0.05)+
  facet_grid(~path)

Alternative Plotting

# Alternative plotting
ggplot(data = dat1 %>% filter(experiment==1), 
       aes(x=trial_type, y = success.bin, color = trial_type), size = 3)+
  geom_point()+
  geom_line(aes(group = interaction(participant_number)))+
  facet_wrap(path~participant_number)

ggplot(data = dat1 %>% filter(experiment==2), 
       aes(x=trial_type, y = success.bin, color = trial_type), size = 3)+
  geom_point()+
  geom_line(aes(group = interaction(participant_number)))+
  facet_wrap(path~participant_number)

# not sure if we will include these plots or not
# ggplot(data =dat1 , aes( x= trial_across_both_experiments, y = success.bin))+
#   geom_point(size = 4, aes( color = trial_type, shape = path))+
#   geom_line(aes(group = participant_number), lwd =1.2)+
#   facet_wrap(~participant_number)
# 
# ggplot(data =dat1 %>% filter(trial_type=="no_belt"), aes( x= trial_across_both_experiments, y = success.bin))+
#   geom_point(size = 4, aes( color = success, shape = path))+
#   geom_line(aes(group = participant_number), lwd =1.2)+
#   facet_wrap(~participant_number)
# 
# ggplot(data =dat1 %>% filter(trial_type=="yes_belt"), aes( x= trial_across_both_experiments, y = success.bin))+
#   geom_point(size = 4, aes( color = success, shape = path))+
#   geom_line(aes(group = participant_number), lwd =1.2)+
#   facet_wrap(~participant_number)

Statistical Methods and Justification

Just a matter of writing out the details of the models and why we chose these models over other potential models.

Outcomes

Model Summary for Experiment 1

Tables containing summary statistics for the model from experiment 1. First table is for fixed effects, the second table is for random effects, and the third table is the variance covariance matrix.

# summary of the fit for mod1_int
sum1 <- summary(glmm1)
# create data frames for each table in sum1 above in order to create nice output
sum1_fix <- as.data.frame(sum1$coefficients$cond)
sum1_ran <- as.data.frame(sum1$varcor$cond)
#sum1_varcov <- as.data.frame(as.matrix(sum1$vcov))

# fixed effects
sum1_fix
##                                  Estimate   Std. Error       z value   Pr(>|z|)
## (Intercept)                  1.672750e+00     0.806436  2.074251e+00 0.03805605
## trial_typeyes_belt           2.231147e+01 25840.151767  8.634420e-04 0.99931107
## pathE1P2                    -5.330867e-08     0.900139 -5.922271e-08 0.99999995
## pathE1P3                     2.164912e+01 18554.658277  1.166775e-03 0.99906905
## trial_typeyes_belt:pathE1P2 -2.231147e+01 25840.151785 -8.634420e-04 0.99931107
## trial_typeyes_belt:pathE1P3 -4.211761e+01 31811.884365 -1.323958e-03 0.99894363
# random effects
sum1_ran
##             X.Intercept.
## (Intercept)     1.672704
# variance-covariance matrix
#sum1_varcov
sum1$vcov
## Conditional model:
##                             (Intercept) trial_typeyes_belt   pathE1P2
## (Intercept)                   0.6503390       1.450719e-01 -0.4051251
## trial_typeyes_belt            0.1450719       6.677134e+08  0.4048848
## pathE1P2                     -0.4051251       4.048850e-01  0.8102501
## pathE1P3                     -0.2729752       3.597054e+03  0.4050922
## trial_typeyes_belt:pathE1P2  -0.1450719      -6.677134e+08 -0.8100099
## trial_typeyes_belt:pathE1P3  -0.1809407      -6.677170e+08 -0.4048519
##                                  pathE1P3 trial_typeyes_belt:pathE1P2
## (Intercept)                 -2.729751e-01               -1.450719e-01
## trial_typeyes_belt           3.622575e+03               -6.677134e+08
## pathE1P2                     4.050922e-01               -8.100100e-01
## pathE1P3                     3.442753e+08               -3.597054e+03
## trial_typeyes_belt:pathE1P2 -3.622575e+03                6.677134e+08
## trial_typeyes_belt:pathE1P3 -3.442790e+08                6.677170e+08
##                             trial_typeyes_belt:pathE1P3
## (Intercept)                               -1.809406e-01
## trial_typeyes_belt                        -6.677171e+08
## pathE1P2                                  -4.048521e-01
## pathE1P3                                  -3.442789e+08
## trial_typeyes_belt:pathE1P2                6.677171e+08
## trial_typeyes_belt:pathE1P3                1.011996e+09

Model Summary for Experiment 2

Tables containing summary statistics for the model from experiment 1. First table is for fixed effects, the second table is for random effects, and the third table is the variance covariance matrix.

# summary of the fit for mod1_int
sum2 <- summary(glmm2)

# create data frames for each table in sum1 above in order to create nice output
sum2_fix <- as.data.frame(sum2$coefficients$cond)
sum2_ran <- as.data.frame(sum2$varcor$cond)
sum2_varcov <- as.data.frame(as.matrix(sum2$vcov)) 

# fixed effects
sum2_fix
##                              Estimate Std. Error    z value     Pr(>|z|)
## (Intercept)                 -2.825638   1.083567 -2.6077180 0.0091148024
## trial_typeyes_belt           6.458669   1.804171  3.5798546 0.0003437855
## pathE2P2                     5.045668   1.509110  3.3434739 0.0008273647
## pathE2P3                     1.849751   1.111120  1.6647629 0.0959600717
## trial_typeyes_belt:pathE2P2 -5.894237   2.060692 -2.8603189 0.0042321523
## trial_typeyes_belt:pathE2P3 -1.849745   1.882099 -0.9828092 0.3257013294
# random effects
sum2_ran
##             X.Intercept.
## (Intercept)     2.172916
# variance-covariance matrix
sum2_varcov
##                                                                                                                                                                                                                                                                                                                                                                                                                                V1
## cond 1.1741183, -1.3999264, -1.3179740, -0.9500006, 1.3601070, 0.9500004, -1.3999264, 3.2550327, 1.9296514, 1.1863673, -3.1722359, -2.3402200, -1.3179740, 1.9296514, 2.2774116, 1.1327558, -2.3530147, -1.1327554, -0.9500006, 1.1863673, 1.1327558, 1.2345866, -1.1601805, -1.2345864, 1.3601070, -3.1722359, -2.3530147, -1.1601805, 4.2464525, 2.3140331, 0.9500004, -2.3402200, -1.1327554, -1.2345864, 2.3140331, 3.5422976

Statistical Inference and Estimation

Estimated Marginal Means

Table and plot of estimated marginal means over the different paths for experiment 1.

# package to examine the estimated marginal means
library(emmeans)
# estimated marginal means
em_glmm1 <- emmeans(glmm1, ~ trial_type | path)
em_glmm1
## path = E1P1:
##  trial_type emmean       SE  df  lower.CL upper.CL
##  no_belt      1.67 8.06e-01 101      0.07     3.27
##  yes_belt    23.98 2.58e+04 101 -51235.93 51283.89
## 
## path = E1P2:
##  trial_type emmean       SE  df  lower.CL upper.CL
##  no_belt      1.67 8.06e-01 101      0.07     3.27
##  yes_belt     1.67 8.06e-01 101      0.07     3.27
## 
## path = E1P3:
##  trial_type emmean       SE  df  lower.CL upper.CL
##  no_belt     23.32 1.86e+04 101 -36784.13 36830.77
##  yes_belt     3.52 1.29e+00 101      0.96     6.07
## 
## Results are given on the logit (not the response) scale. 
## Confidence level used: 0.95
ip_glmm1 <- emmip(em_glmm1, ~ trial_type | path, type = "response", bias.adjust = TRUE)
ip_glmm1

Table and plot of estimated marginal means over the different paths for experiment 2.

# estimated marginal means
em_glmm2 <- emmeans(glmm2, ~ trial_type | path)
em_glmm2
## path = E2P1:
##  trial_type emmean    SE  df lower.CL upper.CL
##  no_belt    -2.826 1.084 101   -4.975   -0.676
##  yes_belt    3.633 1.276 101    1.101    6.165
## 
## path = E2P2:
##  trial_type emmean    SE  df lower.CL upper.CL
##  no_belt     2.220 0.903 101    0.429    4.012
##  yes_belt    2.784 1.023 101    0.755    4.814
## 
## path = E2P3:
##  trial_type emmean    SE  df lower.CL upper.CL
##  no_belt    -0.976 0.713 101   -2.391    0.439
##  yes_belt    3.633 1.276 101    1.101    6.165
## 
## Results are given on the logit (not the response) scale. 
## Confidence level used: 0.95
ip_glmm2 <- emmip(em_glmm2, ~ trial_type | path, type = "response", bias.adjust = TRUE)
ip_glmm2

Prediction Probabilities

Table and plot of prediction probabilities over the different types for experiment 1, separated by trial_type.

# package for prediction probabilities
library(ggeffects)
# plot of prediction probabilities for experiment 1
pred_glmm1 <- ggpredict(glmm1, terms = c("trial_type", "path"))
pred_glmm1 %>% data.frame()
##          x predicted    std.error     conf.low conf.high group
## 1 yes_belt 1.0000000 2.584015e+04 2.220446e-16 1.0000000  E1P1
## 2 yes_belt 0.8419422 8.064359e-01 5.230250e-01 0.9627928  E1P2
## 3 yes_belt 0.9711320 1.287843e+00 7.294042e-01 0.9976238  E1P3
## 4  no_belt 0.8419422 8.064360e-01 5.230249e-01 0.9627928  E1P1
## 5  no_belt 0.8419422 8.064360e-01 5.230249e-01 0.9627928  E1P2
## 6  no_belt 1.0000000 1.855466e+04 2.220446e-16 1.0000000  E1P3
plot(pred_glmm1)

Table and plot of prediction probabilities over the different types for experiment 2, separated by trial_type.

# plot of prediction probabilities for experiment 2
pred_glmm2 <- ggpredict(glmm2, terms = c("trial_type", "path"))
pred_glmm2 %>% data.frame()
##          x  predicted std.error    conf.low conf.high group
## 1  no_belt 0.90203387 0.9030958 0.610638068 0.9818375  E2P2
## 2  no_belt 0.27370854 0.7132346 0.085192385 0.6039681  E2P3
## 3  no_belt 0.05595436 1.0835674 0.007037841 0.3313944  E2P1
## 4 yes_belt 0.94183043 1.0228539 0.685616783 0.9917497  E2P2
## 5 yes_belt 0.97424508 1.2764418 0.756070871 0.9978386  E2P3
## 6 yes_belt 0.97424493 1.2764396 0.756070566 0.9978385  E2P1
plot(pred_glmm2)

Model Diagnostics

Below is a plot of the simulated residuals from the glmm model and a plot to check posterior predictions for experiment 1.

# Model Diagnostics 
library(DHARMa) # package to create interpretable residuals for visualization

# Experiment 1

# residual diagnostic plots
plot(simulateResiduals(glmm1))

# package to check the posterior predictive power for different frequentist models
library(performance)
check_posterior_predictions(glmm1, 100)

Below is a plot of the simulated residuals from the glmm model and a plot to check posterior predictions for experiment 2.

# Model Diagnostics 

# Experiment 1

# residual diagnostic plots
plot(simulateResiduals(glmm2))

# check posterior predictive power
check_posterior_predictions(glmm2, 100)

Paired t-tests - Path Distance Traveled

Here, we are performing paired t-tests on the group means of path distance traveled for the with belt group and the without belt group. Tests ar performed separately for experiments as well as for paths within each experiment.

#------------------------------------------------------------------------------#
###### Paired t-tests for Difference in Means of Path Distance Traveled #######

########################## data setup ##############################

# determining the pairs of participants and paths which result in a success...
# ... both with the belt and without the belt
same_res <- dat1 %>% group_by(participant_number, path) %>% 
  summarise(count_succ = sum(success.bin))

# adding count_succ to the original data, and selecting the columns of interest
dat2 <- left_join(dat1, same_res, by = c("participant_number", "path")) %>%
  select(participant_number, path, trial_type, experiment, count_succ, 
         success.bin, path_distance_meters, time_seconds)

# filter data to only consider successful runs both with and without the belt
succ_dat <- dat2 %>% filter(count_succ == 2)

# select only the columns we need for the t test on path distance traveled
succ_dat_path <- succ_dat %>% select(path_distance_meters, trial_type, experiment, path)

###### separate the data by path and trial_type ######

# Experiment 1
# path distance for with the belt
yes_belt_path_dist11 <- as.data.frame(succ_dat_path %>% 
                                        filter(trial_type == "yes_belt", experiment == 1,
                                               path == "E1P1") %>%
                                        select(path_distance_meters))[, 1]
yes_belt_path_dist12 <- as.data.frame(succ_dat_path %>% 
                                        filter(trial_type == "yes_belt", experiment == 1,
                                               path == "E1P2") %>%
                                        select(path_distance_meters))[, 1]
yes_belt_path_dist13 <- as.data.frame(succ_dat_path %>% 
                                        filter(trial_type == "yes_belt", experiment == 1,
                                               path == "E1P3") %>%
                                        select(path_distance_meters))[, 1]

# path distance for without the belt 
no_belt_path_dist11 <- as.data.frame(succ_dat_path %>% 
                                      filter(trial_type == "no_belt", experiment == 1, 
                                             path == "E1P1") %>%
                                      select(path_distance_meters))[, 1]
no_belt_path_dist12 <- as.data.frame(succ_dat_path %>% 
                                      filter(trial_type == "no_belt", experiment == 1, 
                                             path == "E1P2") %>%
                                      select(path_distance_meters))[, 1]
no_belt_path_dist13 <- as.data.frame(succ_dat_path %>% 
                                      filter(trial_type == "no_belt", experiment == 1,
                                             path == "E1P3") %>%
                                      select(path_distance_meters))[, 1]

# Experiment 2
# path distance for with the belt 
yes_belt_path_dist21 <- as.data.frame(succ_dat_path %>% 
                                       filter(trial_type == "yes_belt", experiment == 2,
                                              path == "E2P1") %>%
                                       select(path_distance_meters))[, 1]
yes_belt_path_dist22 <- as.data.frame(succ_dat_path %>% 
                                       filter(trial_type == "yes_belt", experiment == 2,
                                              path == "E2P2") %>%
                                       select(path_distance_meters))[, 1]
yes_belt_path_dist23 <- as.data.frame(succ_dat_path %>% 
                                       filter(trial_type == "yes_belt", experiment == 2,
                                              path == "E2P3") %>%
                                       select(path_distance_meters))[, 1]

# path distance for without the belt
no_belt_path_dist21 <- as.data.frame(succ_dat_path %>% 
                                       filter(trial_type == "no_belt", experiment == 2,
                                              path == "E2P1") %>%
                                       select(path_distance_meters))[, 1]
no_belt_path_dist22 <- as.data.frame(succ_dat_path %>% 
                                       filter(trial_type == "no_belt", experiment == 2,
                                              path == "E2P2") %>%
                                       select(path_distance_meters))[, 1]
no_belt_path_dist23 <- as.data.frame(succ_dat_path %>% 
                                       filter(trial_type == "no_belt", experiment == 2,
                                              path == "E2P3") %>%
                                       select(path_distance_meters))[, 1]

Visualization

This section consists of plots to visualize the change in path distance traveled between the with belt group and without belt group, in each of the different paths in the two experiments.

# visualizing path distance traveled for the different paths in different experiments
# adjust these plots below for the data conditioned on success
ggplot(data = dat1 %>% filter(experiment==1), aes(x = trial_type, 
                        y = path_distance_meters))+
  geom_boxplot()+
  geom_point( aes(color = path, shape = success), size = 3)+
  geom_line(aes(color = path, group = path))+
  facet_wrap(~participant_number, scales = "free_y")

ggplot(data = dat1 %>% filter(success=="yes", experiment==1), 
       aes(x = interaction(trial_type,path), 
           y = path_distance_meters))+
  facet_wrap(~experiment)+
  geom_boxplot()+
  geom_jitter(width = 0.1, height = 0, aes(color = path))+
  theme(axis.text.x=element_text(angle = 90))

ggplot(data = dat1 %>% filter(experiment==2), aes(x = trial_type, 
                        y = path_distance_meters))+
  geom_boxplot()+
  geom_point( aes(color = path, shape = success), size = 3)+
  geom_line(aes(color = path, group = path))+
  facet_wrap(~participant_number, scales = "free_y")

ggplot(data = dat1 %>% filter(success=="yes", experiment==2), 
       aes(x = interaction(trial_type,path), 
           y = path_distance_meters))+
  facet_wrap(~experiment)+
  geom_boxplot()+
  geom_jitter(width = 0.1, height = 0, aes(color = path))+
  theme(axis.text.x=element_text(angle = 90))

ggplot(data = dat1 %>% filter(success=="yes"), 
       aes(x = interaction(trial_type), 
           y = path_distance_meters))+
  facet_wrap(~experiment)+
  geom_boxplot()+
  geom_jitter(width = 0.1, height = 0, aes(color = trial_type))+
  theme(axis.text.x=element_text(angle = 90))

Statistical Methods and Explanation

The reason for choosing a paired t-test is due to the fact that two populations are dependent as it is the same group of people in the group with the belt and the group without the belt. We are running these tests by conditioning on success and separating by path in each of the two experiments. Since a paired test requires equal sample sizes from the two samples, we can only consider pairs of trials where the individual completed the same path both with and without the belt.

The null hypothesis is that there is no significant difference in group means, and the alternative is that there is a significant difference in the group means. Thus, small p-values (generally p-value < 0.05) imply that we reject the null and may conclude that there is sufficient evidence to conclude there is a significant difference in group means. Otherwise, we are unable to conclude that there is a significant difference between group means.

Outcomes

Results from the paired t-tests for experiment 1. From top to bottom, we see the results from path 1, then path 2, and then path 3.

# run the paired t tests for each path in experiment 1 separately
t.test(yes_belt_path_dist11, no_belt_path_dist11, paired = TRUE)
## 
##  Paired t-test
## 
## data:  yes_belt_path_dist11 and no_belt_path_dist11
## t = -2.1148, df = 13, p-value = 0.05433
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
##  -18.6539762   0.1988958
## sample estimates:
## mean difference 
##        -9.22754
t.test(yes_belt_path_dist12, no_belt_path_dist12, paired = TRUE)
## 
##  Paired t-test
## 
## data:  yes_belt_path_dist12 and no_belt_path_dist12
## t = -1.4077, df = 10, p-value = 0.1895
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
##  -15.357806   3.465379
## sample estimates:
## mean difference 
##       -5.946214
t.test(yes_belt_path_dist13, no_belt_path_dist13, paired = TRUE)
## 
##  Paired t-test
## 
## data:  yes_belt_path_dist13 and no_belt_path_dist13
## t = -1.7376, df = 16, p-value = 0.1015
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
##  -32.08692   3.18014
## sample estimates:
## mean difference 
##       -14.45339

Results from the paired t-tests for experiment 2. From top to bottom, we see the results from path 1, then path 2, and then path 3.

# run the paired t tests for each path in experiment 2 separately
t.test(yes_belt_path_dist21, no_belt_path_dist21, paired = TRUE)
## 
##  Paired t-test
## 
## data:  yes_belt_path_dist21 and no_belt_path_dist21
## t = 134.25, df = 1, p-value = 0.004742
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
##  11.02165 13.32606
## sample estimates:
## mean difference 
##        12.17385
t.test(yes_belt_path_dist22, no_belt_path_dist22, paired = TRUE)
## 
##  Paired t-test
## 
## data:  yes_belt_path_dist22 and no_belt_path_dist22
## t = 0.91666, df = 13, p-value = 0.376
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
##  -5.030105 12.444927
## sample estimates:
## mean difference 
##        3.707411
t.test(yes_belt_path_dist23, no_belt_path_dist23, paired = TRUE)
## 
##  Paired t-test
## 
## data:  yes_belt_path_dist23 and no_belt_path_dist23
## t = 0.26988, df = 5, p-value = 0.798
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
##  -14.36080  17.72989
## sample estimates:
## mean difference 
##        1.684548

Statistical Inference and Estimation

Need to think about what goes here later.

Model Diagnostics

Will fill this in later after thinking about what to include.

Paired t-tests - Time Spent

Here, we are performing paired t-tests on the group means of time spent for the with belt group and the without belt group. Tests ar performed separately for experiments as well as for paths within each experiment.

#------------------------------------------------------------------------------#
############ Paired t-tests for Difference in Means of Time Spent #############

########################## data setup ##############################

# select only the columns we need for the t test on time spent
succ_dat_time <- succ_dat %>% select(time_seconds, trial_type, experiment, path)

# time spent for with the belt for experiment 1
yes_belt_time11 <- as.data.frame(succ_dat_time %>% 
                                   filter(trial_type == "yes_belt", experiment == 1, 
                                          path == "E1P1") %>%
                                   select(time_seconds))[, 1]
yes_belt_time12 <- as.data.frame(succ_dat_time %>% 
                                  filter(trial_type == "yes_belt", experiment == 1, 
                                         path == "E1P2") %>%
                                  select(time_seconds))[, 1]
yes_belt_time13 <- as.data.frame(succ_dat_time %>% 
                                  filter(trial_type == "yes_belt", experiment == 1, 
                                         path == "E1P3") %>%
                                  select(time_seconds))[, 1]

# path distance for without the belt for experiment 1
no_belt_time11 <- as.data.frame(succ_dat_time %>% 
                                  filter(trial_type == "no_belt", experiment == 1, 
                                         path == "E1P1") %>%
                                  select(time_seconds))[, 1]
no_belt_time12 <- as.data.frame(succ_dat_time %>% 
                                 filter(trial_type == "no_belt", experiment == 1, 
                                        path == "E1P2") %>%
                                 select(time_seconds))[, 1]
no_belt_time13 <- as.data.frame(succ_dat_time %>% 
                                 filter(trial_type == "no_belt", experiment == 1, 
                                        path == "E1P3") %>%
                                 select(time_seconds))[, 1]

# time spent for with the belt for experiment 2
yes_belt_time21 <- as.data.frame(succ_dat_time %>% 
                                   filter(trial_type == "yes_belt", experiment == 2, 
                                          path == "E2P1") %>%
                                   select(time_seconds))[, 1]
yes_belt_time22 <- as.data.frame(succ_dat_time %>% 
                                  filter(trial_type == "yes_belt", experiment == 2, 
                                         path == "E2P2") %>%
                                  select(time_seconds))[, 1]
yes_belt_time23 <- as.data.frame(succ_dat_time %>% 
                                  filter(trial_type == "yes_belt", experiment == 2, 
                                         path == "E2P3") %>%
                                  select(time_seconds))[, 1]

# path distance for without the belt for experiment 2
no_belt_time21 <- as.data.frame(succ_dat_time %>% 
                                  filter(trial_type == "no_belt", experiment == 2, 
                                         path == "E2P1") %>%
                                  select(time_seconds))[, 1]
no_belt_time22 <- as.data.frame(succ_dat_time %>% 
                                 filter(trial_type == "no_belt", experiment == 2, 
                                        path == "E2P2") %>%
                                 select(time_seconds))[, 1]
no_belt_time23 <- as.data.frame(succ_dat_time %>% 
                                 filter(trial_type == "no_belt", experiment == 2, 
                                        path == "E2P3") %>%
                                 select(time_seconds))[, 1]

Visualization

This section consists of plots to visualize the change in time spent between the with belt group and without belt group, in each of the different paths in the two experiments.

# visualizing path distance traveled for the different paths in different experiments
# adjust these plots below for the data conditioned on success
ggplot(data = dat1 %>% filter(experiment==1), aes(x = trial_type, 
                        y = time_seconds))+
  geom_boxplot()+
  geom_point( aes(color = path, shape = success), size = 3)+
  geom_line(aes(color = path, group = path))+
  facet_wrap(~participant_number, scales = "free_y")

ggplot(data = dat1 %>% filter(success=="yes", experiment==1), 
       aes(x = interaction(trial_type,path), 
           y = time_seconds))+
  facet_wrap(~experiment)+
  geom_boxplot()+
  geom_jitter(width = 0.1, height = 0, aes(color = path))+
  theme(axis.text.x=element_text(angle = 90))

ggplot(data = dat1 %>% filter(experiment==2), aes(x = trial_type, 
                        y = time_seconds))+
  geom_boxplot()+
  geom_point( aes(color = path, shape = success), size = 3)+
  geom_line(aes(color = path, group = path))+
  facet_wrap(~participant_number, scales = "free_y")

ggplot(data = dat1 %>% filter(success=="yes", experiment==2), 
       aes(x = interaction(trial_type,path), 
           y = time_seconds))+
  facet_wrap(~experiment)+
  geom_boxplot()+
  geom_jitter(width = 0.1, height = 0, aes(color = path))+
  theme(axis.text.x=element_text(angle = 90))

ggplot(data = dat1 %>% filter(success=="yes"), 
       aes(x = interaction(trial_type), 
           y = time_seconds))+
  facet_wrap(~experiment)+
  geom_boxplot()+
  geom_jitter(width = 0.1, height = 0, aes(color = trial_type))+
  theme(axis.text.x=element_text(angle = 90))

Statistical Methods and Explanation

The reason for choosing a paired t-test is due to the fact that two populations are dependent as it is the same group of people in the group with the belt and the group without the belt. We are running these tests by conditioning on success and separating by path in each of the two experiments. Since a paired test requires equal sample sizes from the two samples, we can only consider pairs of trials where the individual completed the same path both with and without the belt.

The null hypothesis is that there is no significant difference in group means, and the alternative is that there is a significant difference in the group means. Thus, small p-values (generally p-value < 0.05) imply that we reject the null and may conclude that there is sufficient evidence to conclude there is a significant difference in group means. Otherwise, we are unable to conclude that there is a significant difference between group means.

Outcomes

Results from the paired t-tests for experiment 1. From top to bottom, we see the results from path 1, then path 2, and then path 3.

# run the paired t tests for each path in experiment 1 separately
t.test(yes_belt_time11, no_belt_time11, paired = TRUE)
## 
##  Paired t-test
## 
## data:  yes_belt_time11 and no_belt_time11
## t = -0.22063, df = 13, p-value = 0.8288
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
##  -40.08371  32.65514
## sample estimates:
## mean difference 
##       -3.714286
t.test(yes_belt_time12, no_belt_time12, paired = TRUE)
## 
##  Paired t-test
## 
## data:  yes_belt_time12 and no_belt_time12
## t = -0.53608, df = 10, p-value = 0.6036
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
##  -42.18866  25.82502
## sample estimates:
## mean difference 
##       -8.181818
t.test(yes_belt_time13, no_belt_time13, paired = TRUE)
## 
##  Paired t-test
## 
## data:  yes_belt_time13 and no_belt_time13
## t = -0.98361, df = 16, p-value = 0.34
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
##  -22.086676   8.086676
## sample estimates:
## mean difference 
##              -7

Results from the paired t-tests for experiment 2. From top to bottom, we see the results from path 1, then path 2, and then path 3.

# run the paired t tests for each path in experiment 2 separately
t.test(yes_belt_time21, no_belt_time21, paired = TRUE)
## 
##  Paired t-test
## 
## data:  yes_belt_time21 and no_belt_time21
## t = 113, df = 1, p-value = 0.005634
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
##  50.1469 62.8531
## sample estimates:
## mean difference 
##            56.5
t.test(yes_belt_time22, no_belt_time22, paired = TRUE)
## 
##  Paired t-test
## 
## data:  yes_belt_time22 and no_belt_time22
## t = 2.1885, df = 13, p-value = 0.04749
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
##   0.1606016 24.8393984
## sample estimates:
## mean difference 
##            12.5
t.test(yes_belt_time23, no_belt_time23, paired = TRUE)
## 
##  Paired t-test
## 
## data:  yes_belt_time23 and no_belt_time23
## t = 0.73086, df = 5, p-value = 0.4977
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
##  -43.21161  77.54495
## sample estimates:
## mean difference 
##        17.16667

Statistical Inference and Estimation

Need to think about what goes here later.

Model Diagnostics

Will fill this in later after thinking about what to include.

Start Bearing

Visualization

library(cowplot) # for grids

# Experiment 1 Path 1
start_nobelt_p <-
ggplot(data = dat1 %>% filter(path=="E1P1"), 
         aes(x = start_bearing_no_belt, y =1))+
  geom_point()+
  geom_point(aes(x = 346, y = 1), size= 3, color = "red")+
  scale_x_continuous(breaks=c(0, 90, 180, 270, 360), limits = c(0, 360))+
  coord_polar(start = 0)+
  theme_bw()

start_belt_p <-
ggplot(data = dat1 %>% filter(path=="E1P1"), 
         aes(x = start_bearing_with_belt, y =1))+
  geom_point()+
  geom_point(aes(x = 346, y = 1), size= 3, color = "red")+
  scale_x_continuous(breaks=c(0, 90, 180, 270, 360), limits = c(0, 360))+
  coord_polar(start = 0)+
  theme_bw()

plot_grid(start_nobelt_p, start_belt_p, ncol = 2, 
          labels = "E1P1")

# Experiment 1 Path 2
start_nobelt_p <-
ggplot(data = dat1 %>% filter(path=="E1P2"), 
         aes(x = `start_bearing_no_belt`, y =1))+
  geom_point()+
  geom_point(aes(x = 143, y = 1), size= 3, color = "red")+
  scale_x_continuous(breaks=c(0, 90, 180, 270, 360), limits = c(0, 360))+
  coord_polar(start = 0)+
  theme_bw()

start_belt_p <-
ggplot(data = dat1 %>% filter(path=="E1P2"), 
         aes(x = `start_bearing_with_belt`, y =1))+
  geom_point()+
  geom_point(aes(x = 143, y = 1), size= 3, color = "red")+
  scale_x_continuous(breaks=c(0, 90, 180, 270, 360), limits = c(0, 360))+
  coord_polar(start = 0)+
  theme_bw()

plot_grid(start_nobelt_p, start_belt_p, ncol = 2, 
          labels = "E1P2")

# Experiment 1 Path 3
start_nobelt_p <-
ggplot(data = dat1 %>% filter(path=="E1P3"), 
         aes(x = `start_bearing_no_belt`, y =1))+
  geom_point()+
  geom_point(aes(x = 302, y = 1), size= 3, color = "red")+
  scale_x_continuous(breaks=c(0, 90, 180, 270, 360), limits = c(0, 360))+
  coord_polar(start = 0)+
  theme_bw()

start_belt_p <-
ggplot(data = dat1 %>% filter(path=="E1P3"), 
         aes(x = `start_bearing_with_belt`, y =1))+
  geom_point()+
  geom_point(aes(x = 302, y = 1), size= 3, color = "red")+
  scale_x_continuous(breaks=c(0, 90, 180, 270, 360), limits = c(0, 360))+
  coord_polar(start = 0)+
  theme_bw()

plot_grid(start_nobelt_p, start_belt_p, ncol = 2, 
          labels = "E1P3")

# Experiment 2 Path 1
start_nobelt_p <-
ggplot(data = dat1 %>% filter(path=="E2P1"), 
         aes(x = `start_bearing_no_belt`, y =1))+
  geom_point()+
  geom_point(aes(x = 115, y = 1), size= 3, color = "red")+
  scale_x_continuous(breaks=c(0, 90, 180, 270, 360), limits = c(0, 360))+
  coord_polar(start = 0)+
  theme_bw()

start_belt_p <-
ggplot(data = dat1 %>% filter(path=="E2P1"), 
         aes(x = `start_bearing_with_belt`, y =1))+
  geom_point()+
  geom_point(aes(x = 115, y = 1), size= 3, color = "red")+
  scale_x_continuous(breaks=c(0, 90, 180, 270, 360), limits = c(0, 360))+
  coord_polar(start = 0)+
  theme_bw()

plot_grid(start_nobelt_p, start_belt_p, ncol = 2, 
          labels = "E2P1")

# Experiment 2 Path 2
start_nobelt_p <-
ggplot(data = dat1 %>% filter(path=="E2P2"), 
         aes(x = `start_bearing_no_belt`, y =1))+
  geom_point()+
  geom_point(aes(x = 97, y = 1), size= 3, color = "red")+
  scale_x_continuous(breaks=c(0, 90, 180, 270, 360), limits = c(0, 360))+
  coord_polar(start = 0)+
  theme_bw()

start_belt_p <-
ggplot(data = dat1 %>% filter(path=="E2P2"), 
         aes(x = `start_bearing_with_belt`, y =1))+
  geom_point()+
  geom_point(aes(x = 97, y = 1), size= 3, color = "red")+
  scale_x_continuous(breaks=c(0, 90, 180, 270, 360), limits = c(0, 360))+
  coord_polar(start = 0)+
  theme_bw()

plot_grid(start_nobelt_p, start_belt_p, ncol = 2, 
          labels = "E2P2")

# Experiment 2 Path 3
start_nobelt_p <-
ggplot(data = dat1 %>% filter(path=="E2P3"), 
         aes(x = `start_bearing_no_belt`, y =1))+
  geom_point()+
  geom_point(aes(x = 358, y = 1), size= 3, color = "red")+
  scale_x_continuous(breaks=c(0, 90, 180, 270, 360), limits = c(0, 360))+
  coord_polar(start = 0)+
  theme_bw()

start_belt_p <-
ggplot(data = dat1 %>% filter(path=="E2P3"), 
         aes(x = `start_bearing_with_belt`, y =1))+
  geom_point()+
  geom_point(aes(x = 358, y = 1), size= 3, color = "red")+
  scale_x_continuous(breaks=c(0, 90, 180, 270, 360), limits = c(0, 360))+
  coord_polar(start = 0)+
  theme_bw()

plot_grid(start_nobelt_p, start_belt_p, ncol = 2, 
          labels = "E2P3")

Statistical Methods and Explanation

Outcome

Statistical Inference and Estimation

Model Diagnostics

End Bearing

Visualization

Statistical Methods and Explanation

Outcome

Statistical Inference and Estimation

Model Diagnostics

Perception

Visualization

Statistical Methods and Explanation

Outcome

Statistical Inference and Estimation

Model Diagnostics